import http from './http'

export interface ApiResponse<T = unknown> {
    code: number,
    message: string,
    data: T
}

export function get<T>(url: string, params?: Record<string, unknown>):Promise<ApiResponse<T>>{
    return http.get(url, {params})
}

export function post<T>(url: string, data?: Record<string, unknown>):Promise<ApiResponse<T>>{
    return http.post(url, data)
}

export function upload(url: string, file: File, fieldName = 'file'): Promise<ApiResponse> {
    const formData = new FormData()
    formData.append(fieldName, file)
    return http.post(url, formData, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

